package config

import (
	"common/helper"
	"database/sql"
)

type CfgAddWage struct {
	Id        string  `json:"id" db:"id" cbor:"id"`
	WinAmount float64 `json:"win_amount" db:"win_amount" cbor:"win_amount"`
	WageMul   float64 `json:"wage" db:"wage" cbor:"wage"`
}

var G_CfgAddWage []CfgAddWage

func AddWageSetRow(rows *sql.Rows) {
	var tVal CfgAddWage
	var err error
	err = rows.Scan(&tVal.WinAmount, &tVal.WageMul)

	if err != nil {
		helper.InfoLog("AddWageSetRow scan err")
		return
	}
	G_CfgAddWage = append(G_CfgAddWage, tVal)
}

func AddWageRemove() {
	G_CfgAddWage = []CfgAddWage{}
}

func GetWageMulByBetMul(winAmount float64) float64 {

	if GetGameCfgInt(CfgGlobalBonusAddWagedSwitch) == 0 {
		return 0.0
	}

	for _, value := range G_CfgAddWage {
		if winAmount >= value.WinAmount {
			return value.WageMul / 100
		}
	}
	return 0.0
}
